<?php
Globals::requireTable('User');

class UserModel extends Config
{
	protected $table;
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->table = new UserTable($config);
	}
	
	public function getUserIdByToken($token,$machine_type=0){
	    $re = $this->table->getRow(array('token'=>$token,'machine_type'=>$machine_type));
	    if($re['id'] < 1){
	        $user['token'] = $token;
	        $user['machine_type'] = $machine_type;
	        $re['id'] = $this->table->add($user,true);
	    }
	    return $re['id'];
	}
	
	public function getUserByUid($uid){
	    return $this->table->getRow($uid);
	}
}
